package com.edu.service.impl;

import com.edu.bean.User;
import com.edu.mapper.UserMapper;
import com.edu.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public List<User> getAllUsers() {
        return userMapper.selectAllUsers();
    }

    @Override
    public String login(String userName, String userPass) {
        User user = userMapper.selectUserByUserName(userName);
        if (user != null) {
            if (userPass.equals(user.getUserPass())) {
                return "登陆成功";
            } else {
                return "密码错误";
            }
        }
        return "账户不存在";
    }

    @Override
    public int register(User user) {
        if (userMapper.selectUserByUserName(user.getUserName()) == null) {
            userMapper.insertUser(user);
            return 1;
        }
        return 0;
    }
}
